﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class EditerForm : Form
    {
        public EditerForm()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }
           
        private int Id;
        public EditerForm (int Id, string Name, int Age,  int Score,string Sex)
        {
            InitializeComponent();
            this.Id = Id;
            textBox1.Text = Name;
            textBox2.Text=Age.ToString();
            textBox3.Text = Score.ToString();
            textBox4.Text =Sex;

        }

        private void button1_Click(object sender, EventArgs e)
        {
          
            var Name  = textBox1.Text;
            var Age = textBox2.Text;
            var Score= textBox3.Text;
            var Sex=textBox4.Text;
            if (this.Id > 0)
            {
                var update = string.Format("update Students set Name ='{0}',Age={1},Score={2} ,Sex='{3}' where Id={4}", Name,Age, Score,Sex,this.Id);
                DbHelper.Addor(update);
                MessageBox.Show("恭喜您更新成功", "消息框");
            }
            else
            { 
            var add =string.Format("insert into Students (Name, Age, Score, Sex) values ('{0}',{1},{2},'{3}')",Name,Age,Score,Sex);
            DbHelper.Addor(add);
            MessageBox.Show("恭喜您添加成功", "消息框");
            }
            this.DialogResult = DialogResult.Yes;
            this.Close();
        

        
        
}

        }

    }

